﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DLMemberPointMS.Entity.POCOModel;
using DLMemberPointMS.Entity.ViewModel;
using DLMemberPointMS.Common;
//using System.Web.Mvc;

namespace DLMemberPointMS.Business
{
    public class LExchangGiftService : BaseService<ExchangGifts>
    {
        BaseService<MemCards> view = new BaseService<MemCards>();



        #region 查找会员
        public OperateResult GetMemCard(string idOrPhone)
        {
            
            if (!string.IsNullOrWhiteSpace(idOrPhone))
            {
                MemCardSEditViewModel Memviewmodel = new MemCardSEditViewModel();
                MemCards resault = null;
                //判断获取到的是id值还是手机号
                if (idOrPhone.Length < 11)
                {
                    resault = view.Find(m => m.MC_CardID == idOrPhone);
                }
                else
                {
                    resault = view.Find(m => m.MC_Mobile == idOrPhone);
                }
                if (resault==null)
                {
                    return new OperateResult(code.Error, "查询失败，没有此会员", Memviewmodel);

                }
                else
                {
                    Memviewmodel.CL_LevelName = resault.CardLevels.CL_LevelName;
                    Memviewmodel.MC_Name = resault.MC_Name;
                    Memviewmodel.CL_ID = resault.CL_ID;
                    Memviewmodel.MC_ID = resault.MC_ID;
                    Memviewmodel.MC_CardID = resault.MC_CardID;
                    Memviewmodel.MC_Point = resault.MC_Point;
                    Memviewmodel.MC_TotalMoney = resault.MC_TotalMoney;
                    return new OperateResult(code.Success, "查询成功", Memviewmodel);
                }
                
            }else
            {
                return new OperateResult(code.Error, "请输入查询数据");

            }




        }
        #endregion
        #region ExchangGifts列表查询
        public OperateResult GetExGift(PageViewModels pageview)
        {
            var query = PredicateExtensions.True<ExchangGifts>();

            int rowCount = 0;//总行数
            var list = GetList(pageview.page, pageview.limit, ref rowCount, query, e => e.EG_ID, true)
                .Select(c => new
                {
                    c.EG_ID,
                    c.EG_Number,
                    c.EG_Photo,
                    c.EG_Point,
                    c.EG_ExchangNum,
                    c.EG_GiftCode,
                    c.EG_GiftName,
                    c.EG_Remark,

                }).ToList();

            if (list.Count == 0)
            {
                return new OperateResult(code.Error, "没有数据哟！");
            }
            else
            {
                return new OperateResult(code.Success, "查询成功", list, rowCount);

            }

        }
        #endregion
    }
}
